package com.wnxy.sddfp.system.controller;

import com.wnxy.sddfp.common.model.dto.bank.CardBindDto;
import com.wnxy.sddfp.common.model.dto.bank.SignatureDto;
import com.wnxy.sddfp.common.model.dto.user.LoginDto;
import com.wnxy.sddfp.common.model.dto.user.UserRegistDto;
import com.wnxy.sddfp.common.model.vo.user.LoginVo;
import com.wnxy.sddfp.common.model.vo.user.UserInfoVo;
import com.wnxy.sddfp.common.result.Result;
import com.wnxy.sddfp.system.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 用户模块
 */
@RestController
@RequestMapping("/user")
public class UserController {

    // 构造器注入
    private final IUserService userService;
    public UserController(IUserService userService) {
        this.userService = userService;
    }

    /**
     * 用户注册
     */
    @PostMapping("/regist")
    public Result regist(@RequestBody @Valid UserRegistDto userRegistDto){
        userService.regist(userRegistDto);
        return Result.ok();
    }

    /**
     * 登录
     */
    @PostMapping("/login")
    public Result<LoginVo> login(@RequestBody LoginDto loginDto) {
        LoginVo loginVo = userService.login(loginDto);
        return Result.ok(loginVo);
    }

    /**
     * 用户绑卡
     */
    @PostMapping("/bank/card/add")
    public Result<SignatureDto> addBankAccount(@RequestBody CardBindDto cardBindDto) {
        SignatureDto signatureDto = userService.addBankAccount(cardBindDto);
        return Result.ok(signatureDto);
    }


    /**
     * 根据用户ID查询
     */
    @GetMapping("/inner/findById/{id}")
    public Result<UserInfoVo> findById(@PathVariable("id") Long userId) {
        UserInfoVo userInfoVo = userService.findUserInfoVo(userId);
        return Result.ok(userInfoVo);
    }
}
